<?php
namespace app\index\service;


use app\index\model\StuffCaiModel;
use app\index\model\StuffChuModel;
use app\index\model\StuffJieModel;
use app\index\model\StuffRuModel;
use app\index\model\StuffTuiModel;

class StuffService extends CommonService
{

    public function create_stuff_cai_number(){
        $tou = 'CG';
        $daystr = substr(date("Ymd"), 2);
        $number = StuffCaiModel::where('number','like','%'.$tou.$daystr.'%')->order('number DESC')->value('number');
        if(!$number){
            $str = $tou.$daystr.'00001';
        }else{
            $str = $tou.((int)str_replace($tou,'',$number)+1);
        }
        return $str;
    }
    public function create_stuff_ru_number(){
        $tou = 'RK';
        $daystr = substr(date("Ymd"), 2);
        $number = StuffRuModel::where('number','like','%'.$tou.$daystr.'%')->order('number DESC')->value('number');
        if(!$number){
            $str = $tou.$daystr.'00001';
        }else{
            $str = $tou.((int)str_replace($tou,'',$number)+1);
        }
        return $str;
    }

    public function create_stuff_chu_number(){
        $tou = 'CK';
        $daystr = substr(date("Ymd"), 2);
        $number = StuffChuModel::where('number','like','%'.$tou.$daystr.'%')->order('number DESC')->value('number');
        if(!$number){
            $str = $tou.$daystr.'00001';
        }else{
            $str = $tou.((int)str_replace($tou,'',$number)+1);
        }
        return $str;
    }

    public function create_stuff_tui_number(){
        $tou = 'TK';
        $daystr = substr(date("Ymd"), 2);
        $number = StuffTuiModel::where('number','like','%'.$tou.$daystr.'%')->order('number DESC')->value('number');
        if(!$number){
            $str = $tou.$daystr.'00001';
        }else{
            $str = $tou.((int)str_replace($tou,'',$number)+1);
        }
        return $str;
    }

    public function create_stuff_jie_number(){
        $tou = 'JSD';
        $daystr = substr(date("Ymd"), 2);
        $number = StuffJieModel::where('number','like','%'.$tou.$daystr.'%')->order('number DESC')->value('number');
        if(!$number){
            $str = $tou.$daystr.'00001';
        }else{
            $str = $tou.((int)str_replace($tou,'',$number)+1);
        }
        return $str;
    }




    public function get_stuff_ru_ishe(){
        return [
            1=>'有采购合同',
            2=>'有采购单',
            0=>'无采购合同/采购单',
            3=>'甲供材料',
        ];
    }

    public function get_stuff_ru_ishe_name($ishe){
        $arr = $this->get_stuff_ru_ishe();
        $str = isset($arr[$ishe]) ? $arr[$ishe] : '';
        return $str;
    }

}
